package com.zhiying.service.impl;

import java.util.List;

import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.session.RowBounds;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.baomidou.mybatisplus.plugins.Page;
import com.zhiying.domain.OS_Category;
import com.zhiying.domain.OS_Product;
import com.zhiying.mybatis.CategoryMapper;
import com.zhiying.page.PageInfo;
import com.zhiying.service.CategoryService;

@Transactional
@Service
@Component
public class CategoryServiceImpl implements CategoryService {

	@Autowired
	private CategoryMapper categoryMapper;
	@Override
	public int SelectCount(int parentId,String search) {
		// TODO Auto-generated method stub
		return categoryMapper.SelectCount(parentId,search);
	}

	@Override
	public List<OS_Category> SelectinfoTwo(PageInfo pageInfo,String search,int parentId) {
		// TODO Auto-generated method stub
		Page<OS_Category> page=new Page<OS_Category>(pageInfo.getCurrent(), pageInfo.getLimit());
		List<OS_Category> categoryList=categoryMapper.SelectinfoTwo(pageInfo, search, page, parentId);
		pageInfo.setTotal(SelectCount(parentId,search));
		return categoryList;
	}

	@Override
	public int UpdateStatus(OS_Category Category) {
		// TODO Auto-generated method stub
		int status=SelectStatusByid(Category.getCategoryId().intValue());
		if(status==0) {
			OS_Category NewCategory=new OS_Category();
			NewCategory.setStatus(1);
			NewCategory.setCategoryId(Category.getCategoryId());
			return categoryMapper.UpdateStatus(NewCategory);
		}else if(status==1) {
			OS_Category NewCategory=new OS_Category();
			NewCategory.setStatus(0);
			NewCategory.setCategoryId(Category.getCategoryId());
			return categoryMapper.UpdateStatus(NewCategory);
		}
		return 0;
	}

	@Override
	public int SelectStatusByid(int CategoryId) {
		// TODO Auto-generated method stub
		return categoryMapper.SelectStatusByid(CategoryId);
	}

	@Override
	public int CountInfoByid(int CategroyId) {
		// TODO Auto-generated method stub
		return categoryMapper.CountInfoByid(CategroyId);
	}

	@Override
	public int DeleteinfoByid(int CategoryId) {
		// TODO Auto-generated method stub
		int Count=CountInfoByid(CategoryId);
		if(Count>0) {
			return 0;
		}else {
			return categoryMapper.DeleteinfoByid(CategoryId);
		}
	}

}
